<?php

/**
 * Created by PhpStorm.
 * User: Short Perton
 * Date: 2016/8/30
 * Time: 11:26
 */
namespace sw\client;

class ChatClient
{

    private $client;

    public function __construct() {
        $this->client = new \swoole_client(SWOOLE_SOCK_TCP);
    }

    public function connect() {
        if (!$this->client->connect("127.0.0.1", 9501, 1)) {
            echo "Error : {$this->client->errMsg}[{$this->client->errCode}]\n";
        }

        fwrite(STDOUT, "请输入消息：");
        $msg = trim(fgets(STDIN));
        $this->client->send($msg);

        $message = $this->client->recv();
        echo "Get Message From Server : {$message}\n";
    }

}